package br.com.seibzhen.specification;

public class Translator {
	
	private static final String WHITESPACE = " ";
	private static final String BLANK_SPACE = "";

	/**
	 * Translate a given method name to a readable one.
	 * It is expected that the method name is written in camel case, such as in
	 * shouldRegisterUseWhenFinancialBalanceIsPositive.
	 * @param name
	 * @return
	 */
	public String translate(String name){
		if(name == null){
			throw new IllegalArgumentException("Name should not be null!");
		}
		
		String readableName = BLANK_SPACE;
		Character character = null;
		
		for(int i = 0; i < name.length(); i++){
			character = name.charAt(i);
			
	        if( Character.isUpperCase(character) && i > 0){
	        	readableName += WHITESPACE;
	        }
	        
	        //Caso seja a primeira letra da sentenca deve ser impresso em maiusculo
	        if( i == 0){
	        	readableName += Character.toUpperCase(character);	        	
	        }else{
	        	readableName += Character.toLowerCase(character);
	        }
	        
		}
		
		return readableName;
	}
}